package damngoodcoffee.smart.commands;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

public class GroupCommand implements Command {
    private static Logger logger = Logger.getLogger(GroupCommand.class
	    .getCanonicalName());
    private List<Command> commands = new ArrayList<Command>();

    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result
		+ ((commands == null) ? 0 : commands.hashCode());
	return result;
    }

    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	GroupCommand other = (GroupCommand) obj;
	if (commands == null) {
	    if (other.commands != null)
		return false;
	} else if (!commands.equals(other.commands))
	    return false;
	return true;
    }

    public void add(Command command) {
	commands.add(command);
    }

    public void execute() throws CommandException {
	for (Command c : commands) {
	    c.execute();
	}
    }

}
